package com.learn.algorithm;

// https://leetcode.cn/problems/min-stack/
public class MinStack {
    int MAX = 8001;

    int[] data;
    int[] min;
    int size;

    public MinStack() {
        data = new int[MAX];
        min = new int[MAX];
        size = 0;
    }

    public void push(int val) {
        data[size] = val;
        if (size == 0) {
            min[size] = val;
        } else {
            min[size] = Math.min(min[size - 1], val);
        }
        size++;
    }

    public void pop() {
        size--;
    }

    public int top() {
        return data[size];
    }

    public int getMin() {
        return min[size];
    }
}
